package com.nali.dal.statement.util.number;

public class NumberWrapper {
	private int level;
	private Number value;

	public NumberWrapper(Number value) {
		this.value = value;
		level = NumberOperateUtil.numberLevel(value);
	}
	
	public Number getValue() {
		return value;
	}
	
	public NumberWrapper add(Number value2) {
		mixLevel(value2);
		value = NumberOperateUtil.add.cal(level, value, value2);
		return this;
	}
	
	public NumberWrapper subtract(Number value2) {
		mixLevel(value2);
		value = NumberOperateUtil.subtract.cal(level, value, value2);
		return this;
	}
	
	public NumberWrapper multiply(Number value2) {
		mixLevel(value2);
		value = NumberOperateUtil.multiply.cal(level, value, value2);
		return this;
	}
	
	public NumberWrapper divide(Number value2) {
		mixLevel(value2);
		value = NumberOperateUtil.divide.cal(level, value, value2);
		return this;
	}
	
	public NumberWrapper beSubtracted(Number value2) {
		mixLevel(value2);
		value = NumberOperateUtil.subtract.cal(level, value2, value);
		return this;
	}
	
	public NumberWrapper beDivided(Number value2) {
		mixLevel(value2);
		value = NumberOperateUtil.divide.cal(level, value2, value);
		return this;
	}

	private void mixLevel(Number value2) {
		if(level==0) {
			return;
		}
		int level2 = NumberOperateUtil.numberLevel(value2);
		level = Math.min(level, level2);
	}

}
